﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace AirWar
{
    public class Bullet
    {
        #region 私有字段
        //子弹所属方
        Side _side;
        //子弹坐标位置
        private Point _position;
        //子弹的发射方向
        private Direction _direction;
        //子弹的步长
        private int _step;
        //子弹的尺寸大小
        private Size _size;
        //子弹是否有效
        private bool _enable = true;
        //子弹图片
        private Bitmap _bulletBmp;
        #endregion
        #region 公有属性
        public Side _Side
        {
            get { return _side; }
            set { _side = value; }
        }
        public Point _Position
        {
            get { return _position; }
            set { _position = value; }
        }
        public Direction _Direction
        {
            get { return _direction; }
            set { _direction = value; }
        }
        public int _Step
        {
            get { return _step; }
            set { _step = value; }
        }
        public Size _Size
        {
            get { return _size; }
            set { _size = value; }
        }
        public bool _Enable
        {
            get { return _enable; }
            set { _enable = value; }
        }
        #endregion

        public Bullet(Side side)
        { 
            //设置子弹所属方
            _side = side;
            //if(根据子弹所属方装载子弹图片和步长）
            if (side == Side.Me)
            {
                _bulletBmp = new Bitmap("Image\\myBullet.png");
                _direction = Direction.Down;
                _step = 20;
            }
            else
            {
                _bulletBmp = new Bitmap("Image\\enemyBullet.png");
                _direction = Direction.Up;
                _step = 10;
            }
            //设置子弹透明色
            _bulletBmp.MakeTransparent(Color.Black);

            //设置子弹尺寸
            _size = new Size(_bulletBmp.Width, _bulletBmp.Height);
        }
        //子弹绘制
        public void DrawMe(Graphics g)
        {
            g.DrawImage(_bulletBmp, _position);
        }
        //子弹移动
        public void Move()
        {
            //我方子弹上移
            if (_side == Side.Me)
                _position.Y = _position.Y - _step;
            //敌方下移
            else
                _position.Y = _position.Y + _step;
        }
    }
}
